/* GUI CONVERTED from ecmt08.p (converter v1.75) Mon Aug 14 12:27:17 2000 */
/* ecmt08.p - ECN MAINTENANCE Copy from Product Structure               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 7.4      LAST EDIT: 07/01/93   BY: pma     *H013*          */
/* REVISION: 7.4      LAST EDIT: 05/14/94   BY: QZL     *H370* sr101810 */
/* REVISION: 7.4      LAST EDIT: 10/27/94   MODIFIED BY: ame *H578*     */
/* REVISION: 7.4      LAST EDIT: 11/15/94   BY: qzl     *H596*          */
/* REVISION: 7.4      LAST EDIT: 02/08/95   BY: cpp     *H0B7*          */
/* REVISION: 7.4      LAST EDIT: 12/30/95   BY: jzs     *H0HM*          */
/* REVISION: 7.4      LAST EDIT: 12/30/95   BY: qzl     *H0J1*          */
/* REVISION: 8.6      LAST EDIT: 06/06/96   BY: Mariya Kutwal *K00C*    */
/* REVISION: 8.6      LAST EDIT: 02/27/97   BY: *H0SY*  Russ Witt       */
/* REVISION: 8.6      LAST MODIFIED: 08/13/97   BY: Joe Gawel    *K0H5* */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane    */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 07/14/98   BY: *J2RV* Niranjan R.  */
/* REVISION: 8.6E     LAST MODIFIED: 07/29/98   BY: *J2V1* Rajesh Talele */
/* REVISION: 9.0      LAST MODIFIED: 01/03/00   BY: *K24Y* Rajesh Thomas */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00 BY: *N0KW* Jacolyn Neder    */
/*hk-s-010                  by: mage             date: 12/30/03                */

/*H0HM*/ {mfdeclre.i}
{gplabel.i &ClearReg=yes} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE ecmt08_p_1 "Ph"
/* MaxLen: Comment: */

&SCOPED-DEFINE ecmt08_p_2 "/no"
/* MaxLen: Comment: */

/*K24Y** &SCOPED-DEFINE ecmt08_p_3 "DUE TO WORKFILE LIMIT." */
/* MaxLen: Comment: */

&SCOPED-DEFINE ecmt08_p_4 " Structure/Formula Copy "
/* MaxLen: Comment: */

/*K24Y** &SCOPED-DEFINE ecmt08_p_5 "LISTING TRUNCATED" */
/* MaxLen: Comment: */

&SCOPED-DEFINE ecmt08_p_6 "Levels"
/* MaxLen: Comment: */

&SCOPED-DEFINE ecmt08_p_7 "Level"
/* MaxLen: Comment: */

/*J2RV*/ /* CHANGED "WARNING" TO "Warning" SO THAT IT CAN BE TRANSLATED */
/*K24Y** &SCOPED-DEFINE ecmt08_p_8 "Warning" */
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

     {ecmtparm.i}
/*H0HM*  {ecwndvar.i}  scrolling window variables */
/*H0HM*/ {wndvar2.i}  /* scrolling window variables */

define variable comp like ps_comp.
define variable level as integer.
define variable maxlevel as integer format ">>>" label {&ecmt08_p_6}.
define variable eff_date like ar_effdate.
define variable parent like ps_par.
define variable desc1 like pt_desc1.
define variable um like pt_um.
define variable phantom like mfc_logical format "yes" label {&ecmt08_p_1}.
define variable iss_pol like pt_iss_pol format {&ecmt08_p_2}.
define variable record as integer extent 100.
define variable lvl as character format "x(7)" label {&ecmt08_p_7}.
define variable ecmid like wo_lot.
define variable dbase like si_db.
/*K24Y** define variable maxwkfl as integer. */
/*K24Y** define variable k as integer.       */
/*H370*/ define variable rev like pt_rev.
/*H370*/ define buffer ecmmstr for ecm_mstr.

/*K24Y*/ /* WORKFILE pswkfl IS REPLACED  BY A TEMP-TABLE */
/*K24Y** define workfile pswkfl */
/*K24Y*/ define temp-table pswkfl
           field psstar  as character format "x(1)"
           field pslvl   like lvl
           field pscomp  like ps_comp
           field psdesc  like desc1
           field psref   like ps_ref
/*hk-s-010*/ FIELD pspar LIKE ps_par
           field psrecid as recid.

/*K00C* pcc_ctrl table now replaces qad_wkfl where qad_key1 = ECN-CTRL */
/*K00C*  find first qad_wkfl no-lock where qad_key1 = "ECN-CTRL" no-error.  */
/*K00C*  if available qad_wkfl then maxwkfl = qad_decfld[15].               */
/*K00C*/ find first pcc_ctrl no-lock no-error.
/*K24Y** /*K00C*/ if available pcc_ctrl then maxwkfl = pcc_max_wkfl. */
/*K24Y**     else maxwkfl = 250. */

     find ecm_mstr where recid(ecm_mstr) = ecm_recid
     exclusive-lock no-error no-wait.
     if locked(ecm_mstr) then do:
        msgnbr = 7422.  /* RECORD LOCKED BY ANOTHER USER, TRY LATER */
        warnlvl = 4.
        return.
     end.
     if not available (ecm_mstr) then do:
        msgnbr = 5630.  /* PROCESS NOT COMPLETE */
        warnlvl = 2.
        return.
     end.

     eff_date = today.

     FORM /*GUI*/ 
        space(1)
        parent
        desc1
        um
        eff_date
/*H370*/    rev
        maxlevel
     with frame ecmt08a width 80 attr-space no-underline
     title color normal (getFrameTitle("STRUCTURE/FORMULA_COPY",32)) THREE-D /*GUI*/.


     /* SET EXTERNAL LABELS */
     setFrameLabels(frame ecmt08a:handle).

     /* SET PARENT TO GLOBAL PART NUMBER */
     parent = global_part.
     repeat with frame ecmt08a:
/*GUI*/ if global-beam-me-up then undo, leave.

        maxlevel = 1.
/*K24Y** k = 0. */
        pause 0.

/*H578*     for each pswkfl:*/
/*H578*/    for each pswkfl exclusive-lock:
           delete pswkfl.
        end.

        update parent eff_date
/*H370*/    rev
        maxlevel with frame ecmt08a editing:

           if frame-field = "parent" then do:
          /* FIND NEXT/PREVIOUS RECORD */
          {mfnp.i bom_mstr parent bom_parent parent bom_parent
              bom_parent}

          if recno <> ? then do:
             parent = bom_parent.
             display bom_parent @ parent.
             find pt_mstr where pt_part = parent no-lock no-error.
             if available pt_mstr then display pt_desc1 @ desc1
             pt_um @ um.
             else display bom_desc @ desc1 bom_batch_um @ um.
             recno = ?.
          end.
           end.
           else do:
          status input.
          readkey.
          apply lastkey.
           end.
        end.

/*H370*/    if rev <> "" then do:
/*H370*/       for each ecmmstr no-lock where ecm_eff_date <> ?, each ecd_det
/*H370*/       no-lock where ecd_nbr = ecmmstr.ecm_nbr and ecd_new_rev = rev
/*H370*/       break by ecm_eff_date descending:
/*H370*/          if ecd_part = parent then do:
/*H370*/             eff_date = ecm_eff_date.
/*H370*/             leave.
/*H370*/          end.
/*H370*/       end.
/*H370*/    end.

        desc1 = "".
        um = "".

        find pt_mstr use-index pt_part where pt_part = parent
        no-lock no-error.
        if available pt_mstr then do:
           assign um = pt_um
           desc1 = pt_desc1
          parent = pt_part.
        end.
        else do:
           find bom_mstr no-lock where bom_parent = parent no-error.
           if available bom_mstr then do:

/*J2V1**  {fsbomv.i bom_parent 2}  */

/*J2V1*/   if bom_fsm_type = "FSM"
/*J2V1*/     then do:
/*J2V1*/        {mfmsg.i 7492 2}
/*J2V1*/        undo, retry.
/*J2V1*/   end.

          assign um = bom_batch_um
          parent = bom_parent.
           end.
        end.

        if not available pt_mstr and not available bom_mstr then do:
           hide message no-pause.
           {mfmsg.i 17 3}
           /* PART NUMBER DOES NOT EXIST. */
           display desc1 um.
/*H596*/       pause.
           undo, retry.
        end.

        display parent desc1 um.

        assign
           level = 1
               comp = parent
/*H0SY*/       repaint = yes
               maxlevel = min(maxlevel,99).

        find first ps_mstr use-index ps_parcomp where ps_par = comp
        no-lock no-error.
        repeat:

           if not available ps_mstr then do:
          repeat:
             level = level - 1.
             if level < 1 then leave.
             find ps_mstr where recid(ps_mstr) = record[level]
             no-lock no-error.
             comp = ps_par.
             find next ps_mstr use-index ps_parcomp where ps_par = comp
             no-lock no-error.
             if available ps_mstr then leave.
          end.
           end.
           if level < 1 then leave.

           if eff_date = ? or (eff_date <> ? and
           (ps_start = ? or ps_start <= eff_date)
           and (ps_end = ? or eff_date <= ps_end)) then do:

          assign um = ""
              desc1 = ""
            iss_pol = no
            phantom = no.

          find pt_mstr where pt_part = ps_comp no-lock no-error.
          if available pt_mstr then do:
             assign um = pt_um
             desc1 = pt_desc1
               iss_pol = pt_iss_pol
               phantom = pt_phantom.
          end.
          else do:
             find bom_mstr no-lock where bom_parent = ps_comp no-error.
             if available bom_mstr then
             assign um = bom_batch_um
             desc1 = bom_desc.
          end.

          record[level] = recid(ps_mstr).
          lvl = ".......".
          lvl = substring(lvl,1,min(level - 1,6)) + string(level).
          if length(lvl) > 7
          then lvl = substring(lvl,length(lvl) - 6,7).

/*K24Y**  k = k + 1. */
          create pswkfl.

/*K24Y**BEGIN DELETE SECTION
 *
 *        if k >= maxwkfl then do:
 * /*J2RV**     assign pslvl = "WARNING" */
 * /*J2RV*/     assign pslvl = {&ecmt08_p_8}
 *             pscomp = {&ecmt08_p_5}
 *             psdesc = {&ecmt08_p_3}.
 *           leave.
 *        end.
 *        else
 *
 *K24Y**END DELETE SECTION */

          do:
             assign psrecid = recid(ps_mstr)
                pslvl = lvl
                pscomp = ps_comp
                psdesc = desc1
                psref = ps_ref
/*hk-s-010*/    pspar = ps_par.
          end.

          if level < maxlevel or maxlevel = 0 then do:
             comp = ps_comp.
             level = level + 1.
             find first ps_mstr use-index ps_parcomp
             where ps_par = comp no-lock no-error.
          end.
          else do:
             find next ps_mstr use-index ps_parcomp where ps_par = comp
             no-lock no-error.
          end.
           end.
           else do:
          find next ps_mstr use-index ps_parcomp where ps_par = comp
          no-lock no-error.
           end.
        end.

        window_row = 10.
        window_down = 8.
        pause 0.

/*hk-s-010   **********add **************************/
   FOR EACH pswkfl :
      FIND bom_mstr WHERE bom_parent = pspar AND bom__chr01 = ecm_user1 NO-LOCK NO-ERROR.
      IF NOT AVAILABLE bom_mstr  THEN DELETE pswkfl.
   END.
/*hk-s-010   **********add **************************/
/*H0HM* use new standard include windowx.i when $help=no *****************
*           {ecwind01.i &file = pswkfl
*                    &display = "psstar     no-label
*                                pslvl
*                                pscomp
*                                psdesc
*                                psref"
*                &index-fld1 = pscomp
*                &index-fld2 = pscomp
*                &frametitle = """"
*                    &return = yes
*                    &multi  = no
*                       &tag = psstar
*                     &width = "width 80"
*                     &help  = no
*                  &helpfile = qad_wkfl
*                 &helpfield = qad_charfld[1]
*                  &helpdisp = "qad_key1"
*                 &helpframe = "chsa"
*           }
*H0HM***************************************************************/
/*H0HM*/    {windowx.i
           &file       = pswkfl
           &display    = "psstar no-label pslvl pscomp psdesc psref"
           &index-fld1 = pscomp
           &index-fld2 = pscomp
           &frametitle = """"
           &framephrase = "width 80"
           &return     = no
           &recid-var  = global_recid
           &tag-var    = psstar
           &tag-val1   = ""*""
           &tag-val2   = """"
           &tag-all    = no
        }

/*H0HM*     if lastkey = keycode("GO") or lastkey = keycode("F1")
******      or keyfunction(lastkey) = "GO" */

/*H0HM*/    if keyfunction(lastkey) = "GO" or lastkey = keycode("RETURN")
/*H0HM*/    then do:

           msgnbr = 5630. /* PROCESS NOT COMPLETE */
           warnlvl = 2.

           for each pswkfl where psstar = "*":
          find ps_mstr no-lock where recid(ps_mstr) = psrecid no-error.
          if available ps_mstr then do:
             find bom_mstr no-lock where bom_parent = ps_par no-error.
             find ecd1_det exclusive-lock where ecd1_nbr = ecm_nbr
             and ecd1_par = ps_par and ecd1_comp = ps_comp
             and ecd1_ref = ps_ref no-error.
             if not available ecd1_det then do:
            create ecd1_det.
            assign ecd1_nbr = ecm_nbr
                   ecd1_par = ps_par
                   ecd1_comp = ps_comp
                   ecd1_ref = ps_ref
                   ecd1_batch_pct = ps_batch_pct
                   ecd1_item_no = ps_item_no
                   ecd1_op = ps_op
                   ecd1_qty_per = ps_qty_per
                   ecd1_qty_per_b = ps_qty_per_b
                   ecd1_qty_type = ps_qty_type
                   ecd1_rmks = ps_rmks
                   ecd1_scrp_pct = ps_scrp_pct
                   ecd1_batch = 1
                   ecd1_process = "T-13"
                   ecd1__qad01 = no
                   ecd1__qad02 = ps_start
                   ecd1__qad03 = ps_ps_code
                   ecd1__qad04 = string(integer(ps_mandatory))
                   ecd1__qad05 = string(integer(ps_default)).
/*K0H5*/        assign
/*K0H5*/           ecd1_lt_off    = ps_lt_off
/*K0H5*/           ecd1_fcst_pct  = ps_fcst_pct
/*K0H5*/           ecd1_group     = ps_group
/*K0H5*/           ecd1_psprocess = ps_process.

            if available bom_mstr
            and bom_batch <> 0 and bom_batch <> 1
            then assign ecd1_batch = bom_batch
                    ecd1_batch_um = bom_batch_um.
/*K0H5* /*H0J1*/                find qad_wkfl exclusive-lock where
*/
/*K0H5* /*H0J1*/                qad_key1 = "ECN-STRUCTURE" and               */
/*K0H5* /*H0J1*/                qad_key2 = string(recid(ecd1_det)) no-error. */
/*K0H5* /*H0J1*/                if not available qad_wkfl then do:           */
/*K0H5* /*H0J1*/                   create qad_wkfl.                          */
/*K0H5* /*H0J1*/                   assign qad_key1 = "ECN-STRUCTURE"         */
/*K0H5* /*H0J1*/                   qad_key2 = string(recid(ecd1_det)).       */
/*K0H5* /*H0J1*/                end.                                         */
/*K0H5* /*H0J1*/                assign qad_decfld[1]  = ps_lt_off            */
/*K0H5* /*H0J1*/                       qad_decfld[2]  = ps_fcst_pct          */
/*K0H5* /*H0J1*/                       qad_charfld[1] = ps_group             */
/*K0H5* /*H0J1*/                       qad_charfld[2] = ps_process.          */
             end.
          end.
           end. /*for each pswkfl*/
/*H0B7*/       do on endkey undo, leave:
           {mfmsg.i 1107 1} /*PROCESS COMPLETE*/
           pause.
/*H0B7*/       end.
           msgnbr = 0.
           warnlvl = 1.
        end. /*if GO*/
        else apply lastkey.
     end.
/*GUI*/ if global-beam-me-up then undo, leave.

